#include <bits/stdc++.h>

using namespace std;
struct node
{
   int data;
   node* left;
   node* right;
};
void insertNode(node* &root,int x)
{
    if (root==nullptr)
    {
        root=new node;
        root->data=x;
        root->left=nullptr;
        root->right=nullptr;
        return;
    }
    if (x<root->data)
    {
        insertNode(root->left,x);
    }
    else
    {
        insertNode(root->right,x);
    }
}
void preOrder(node* root,vector<int>&v)
{
    if (root==nullptr)
    {
        return;
    }
    v.push_back(root->data);
    preOrder(root->left,v);
    preOrder(root->right,v);
}
void preOrderMirror(node* root,vector<int>&v)
{
    if (root==nullptr)
    {
        return;
    }
    v.push_back(root->data);
    preOrderMirror(root->right,v);
    preOrderMirror(root->left,v);
}
void postOrder(node* root,vector<int>&v)
{
    if (root==nullptr)
    {
        return;
    }
    postOrder(root->left,v);
    postOrder(root->right,v);
    v.push_back(root->data);
}
void postOrderMirror(node* root,vector<int>&v)
{
    if (root==nullptr)
    {
        return;
    }
    postOrderMirror(root->right,v);
    postOrderMirror(root->left,v);
    v.push_back(root->data);
}
vector<int> origin,pre_seq,preM,post_seq,postM;
int main_1043()
{
    int n,data;
    scanf("%d",&n);
    node* root=nullptr;
    for (size_t i=0;i<n ;++i )
    {
        scanf("%d",&data);
        origin.push_back(data);
        insertNode(root,data);
    }
    preOrder(root,pre_seq);
    preOrderMirror(root,preM);
    postOrder(root,post_seq);
    postOrderMirror(root,postM);
    if (origin==pre_seq)
    {
        printf("YES\n");
        for (size_t i=0;i<(post_seq.size()-1);++i )
        {
            printf("%d ",post_seq[i]);
        }
        printf("%d",post_seq[post_seq.size()-1]);
    }
    else if(origin==preM)
    {
        printf("YES\n");
        for (size_t i=0;i<(postM.size()-1);++i )
        {
            printf("%d ",postM[i]);
        }
        printf("%d",postM[postM.size()-1]);

    }
    else
    {
        printf("NO\n");
    }
    return 0;
}
